/**
 *FileRenderer.java
 *@anthor Daniel Liu
 *2006-4-28 2:47:16
 **/
package org.lex.explorer.file;

import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import org.lex.explorer.FileInfo;
import org.lex.swing.table.AutoResizeUtils;


public class FileNameRenderer extends DefaultTableCellRenderer {
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		FileInfo file = (FileInfo) value;
		this.setIcon(file.getIcon());

		AutoResizeUtils.reportWidth(table, 0, this.getPreferredSize().width);
		super.getTableCellRendererComponent(table, file.getName(), isSelected, hasFocus, row, column);

		return this;
	}

	public void setBounds(int x, int y, int width, int height) {
		if (getHorizontalAlignment() == 10)
			width = Math.min(width, getPreferredSize().width + 4);
		else
			x -= 4;

		super.setBounds(x, y, width, height);
	}
}
